package test.orwapkg;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileReaderTester {
	public static void main(String[] args){
		String path = "D:\\myfile.txt";
		try {
			FileReader fr = new FileReader(path);
			BufferedReader bfr = new BufferedReader(fr);
			System.out.println(bfr.readLine());
			bfr.close();
			
			FileReader fr1 = new FileReader(path);
			BufferedReader bfr1 = new BufferedReader(fr1);
			int readChar;
			while((readChar = bfr1.read()) != -1){
				//System.out.println("in while");
				System.out.print((char)readChar);
			}
			bfr1.close();
		} catch (IOException e) {
			if (e instanceof FileNotFoundException) {
				System.err.println("File not found!!!");
			}else
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
				
		try {
			String writePath = "D:\\javaCreatedFile.txt";
			BufferedWriter fw = new BufferedWriter(new FileWriter(writePath));
			fw.write("Heyyyy This is java created file!!");
			fw.newLine();
			fw.write("second line.....");
			fw.flush();
			fw.close();
			BufferedReader bfrWritten = new BufferedReader(new FileReader(writePath));
			System.out.println("\n");
			String str;
			while ((str = bfrWritten.readLine()) != null ){
				System.out.println(str);
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	

}
